Skip to content

Conversation

@j-t-1
Copy link
Contributor

@j-t-1 j-t-1 commented Jul 16, 2025

Sets entries in a page object’s additional-actions dictionary.

@j-t-1
Copy link
Contributor Author

j-t-1 commented Jul 16, 2025

Ideally want to be able to add open and close actions. To avoid a future deprecation, can we add this as _add_js for now?

@stefan6419846
Copy link
Collaborator

To avoid a future deprecation, can we add this as _add_js for now?

I do not understand what you are referring to. Could you please elaborate?

@j-t-1
Copy link
Contributor Author

j-t-1 commented Jul 16, 2025

I could have described better...

def add_js(self, javascript: str, /, *, open_action: bool = True) -> None:

Currently adds either open or close page action. To be able to add both will require modifying the function signature. Or maybe change it so that if given an open action keeps any close action and vice versa.

@stefan6419846
Copy link
Collaborator

We shouldn't have public API that is internal as it might break in the future.

Do you have an actual use case for implementing this? Or is this just because the implementation allows this? I have to be honest that I personally never actively used Javascript in PDF files.

@j-t-1
Copy link
Contributor Author

j-t-1 commented Jul 16, 2025

Let me know if you have a good way to modify this, or the functionality requirements needed.

Currently use the catalog OpenAction but the JavaScript at page-level is more flexible to only run the JavaScript once opening or closing a page.

Will also do a new PR for these tests, as could be in same function?

def test_add_js(pdf_file_writer):
pdf_file_writer.add_js("this.print({bUI:true,bSilent:false,bShrinkToFit:true});")
assert (
"/Names" in pdf_file_writer._root_object
), "add_js should add a name catalog in the root object."
assert (
"/JavaScript" in pdf_file_writer._root_object["/Names"]
), "add_js should add a JavaScript name tree under the name catalog."
def test_added_js(pdf_file_writer):
def get_javascript_name() -> Any:
assert "/Names" in pdf_file_writer._root_object
assert "/JavaScript" in pdf_file_writer._root_object["/Names"]
assert "/Names" in pdf_file_writer._root_object["/Names"]["/JavaScript"]
return pdf_file_writer._root_object["/Names"]["/JavaScript"]["/Names"][
-2
] # return -2 in order to get the latest javascript
pdf_file_writer.add_js("this.print({bUI:true,bSilent:false,bShrinkToFit:true});")
first_js = get_javascript_name()
pdf_file_writer.add_js("this.print({bUI:true,bSilent:false,bShrinkToFit:true});")
second_js = get_javascript_name()
assert (
first_js != second_js
), "add_js should add to the previous script in the catalog."

@stefan6419846
Copy link
Collaborator

Let me know if you have a good way to modify this, or the functionality requirements needed.

I am not completely sure if I can follow you here, but I would just let the user pass the NameObject and document the basics.

Will also do a new PR for these tests, as could be in same function?

Sorry, but I am rather confused what you want to say/ask with this.

@j-t-1
Copy link
Contributor Author

j-t-1 commented Jul 16, 2025

Modified. Is easier to pass a str.

Ignore the comment on tests.

@stefan6419846 can this PR be merged?

@codecov
Copy link

codecov bot commented Jul 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.09%. Comparing base (0ceb8a4) to head (4c0b19e).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3382      +/-   ##
==========================================
+ Coverage   96.97%   97.09%   +0.11%     
==========================================
  Files          54       56       +2     
  Lines        9337     9668     +331     
  Branches     1711     1750      +39     
==========================================
+ Hits         9055     9387     +332     
  Misses        168      168              
+ Partials      114      113       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stefan6419846 stefan6419846 added needs-discussion The PR/issue needs more discussion before we can continue on-hold PR requests that need clarification before they can be merged.A comment must give details labels Sep 20, 2025
@j-t-1 j-t-1 closed this Oct 7, 2025
@j-t-1
Copy link
Contributor Author

j-t-1 commented Oct 7, 2025

An alternative interface will be used to add actions.

@j-t-1 j-t-1 deleted the javascript branch October 20, 2025 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-discussion The PR/issue needs more discussion before we can continue on-hold PR requests that need clarification before they can be merged.A comment must give details

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants